﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections;
using Yd.CommCls;
using Yd.Domain.DAL;
using System.Data;
using System.Web.UI.HtmlControls;
using Yd.BLL;
using System.Text.RegularExpressions;

namespace Yd.Util
{
    public class Base : Page
    {
        public CommBll cbll = new CommBll();
        public CommDAL commdal = new CommDAL();
        private int _PageSize = 10;

        public string NoHTML(string Htmlstring)
        {
            Htmlstring = Regex.Replace(Htmlstring, "<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "-->", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "<!--.*", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(amp|#38);", "&", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(lt|#60);", "<", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(gt|#62);", ">", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(iexcl|#161);", "\x00a1", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(cent|#162);", "\x00a2", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(pound|#163);", "\x00a3", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, "&(copy|#169);", "\x00a9", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
            Htmlstring = Htmlstring.Replace("<", "");
            Htmlstring = Htmlstring.Replace(">", "");
            return Htmlstring;
        }
        /// <summary>
        /// 每页的记录数
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize;
            }
            set
            {
                _PageSize = value;
            }
        }

        public string getfilename(string files)
        {
            if (files.IndexOf(".") != -1)
            {
                return files.ToString().Trim().Substring(0,files.ToString().Trim().LastIndexOf("."));
            }
            return files;
        }

        public string subs(string str,int strlen=2)
        {
            if (str.Trim().Length <= strlen)
            {

                return str.Trim().Substring(0,1)+"*";
            }

            string s = str.Trim();
            string s1 = "";
            for (int i = strlen; i < s.Length; i++)
            {
                s1 = s1 + "*";
            }

            return s.Substring(0, strlen) + s1;

        }

        public string subsf(string str, int strlen = 5)
        {
            if (str.Trim().Length <= strlen)
            {
                return str.Trim();
            }
            return str.Substring(0, strlen);

        }

        private string _ResultMsg = "";
        /// <summary>
        /// 结果信息
        /// </summary>
        public string ResultMsg
        {
            get
            {
                return _ResultMsg;
            }
            set
            {
                _ResultMsg = value;
            }
        }


        private int _PageStyle = 1;
        /// <summary>
        /// 分页的样式
        /// </summary>
        public int PageStyle
        {
            get
            {
                return _PageStyle;
            }
            set
            {
                _PageStyle = value;
            }
        }

        public string fj(object fj)
        {
            if (fj == null)
            {
                return "";
            }
            if (string.IsNullOrEmpty(fj.ToString()))
            {
                return "";
            }
            return "<a href=\"" + fj.ToString() + "\" style=\"color:Blue;\">附件</a>";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string getName()
        {
            return CommCls.CommUtils.GetUserName();
        }

        public string getcurdate()
        {
            return DateTime.Now.ToShortDateString();
        }

        public string getwebtitle()
        {
            DataSet ds = commdal.GetWebSite();
            if (ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["WebTitle"].ToString().Trim();
            }
            return "宽客——为您量身定制的融资伙伴";
        }

        /// <summary>
        /// 用户可用余额
        /// </summary>
        /// <returns></returns>
        public string getyhYue()
        {
            DataSet ds = commdal.QueryObjectAllSql("select * from tz_user where Id="+CommCls.CommUtils.GetUserId());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["zfye"].ToString();
            }
            return "0.0";
        }

        public string gettk()
        {
            DataSet ds = commdal.QueryObjectAllSql("select tkpwd from tz_user where Id=" + CommCls.CommUtils.GetUserId());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["tkpwd"].ToString();
            }
            return "";
        }

        public string getyhYue1()
        {
            DataSet ds = commdal.QueryObjectAllSql("select * from tz_user where Id=" + CommCls.CommUtils.GetUserId());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return (ds.Tables[0].Rows[0]["zfye"].ToString().StrTodecimal()+ds.Tables[0].Rows[0]["djye"].ToString().StrTodecimal())+"";
            }
            return "0.0";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sortid"></param>
        /// <returns></returns>
        public string GetSortName(string sortid)
        {
            DataSet ds = commdal.QueryObjectAllSql("select SortName from Hr_Sort where Id=" + sortid.Trim());
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return "<a href='#'>"+ds.Tables[0].Rows[0]["SortName"].ToString().Trim()+"</a>";
            }
            return "";
        }

        public string getnewszx(string fdate)
        {
            DateTime ds = fdate.StrToDateTime();
            TimeSpan ts = DateTime.Now - ds;
            if (ts.TotalHours <= 72)
            {
                return "<img src='Images/new.gif'>";
            }
            return "";
        }


        public void ShowTs(Literal _fliteral)
        {
            _fliteral.Text = "1";
            DataSet ds = commdal.GetWebInfo();
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                DateTime _DT = DateTime.Now;
                DateTime dt1 = ds.Tables[0].Rows[0]["CreateDate"].ToString().StrToDateTime();
                TimeSpan tsDay = _DT - dt1;
                int dayCount = (int)tsDay.TotalDays;
                if (dayCount != 0)
                    _fliteral.Text = dayCount.ToString();
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="_date"></param>
        /// <returns></returns>
        public string FormateShortDate(string _date)
        {
            return _date.StrToDateTime().ToShortDateString();
        }

        public string FormateShortDate111(string _date)
        {
            return _date.StrToDateTime().ToString("M-d");
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetPassWord(int num=0)
        {
            DataSet ds = commdal.GetWebSite();
            string _p = "123432";
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                if (num == 0)
                {
                    _p = ds.Tables[0].Rows[0]["Pwd"].ToString().Trim();
                }
                else if (num == 1)
                {
                    _p = ds.Tables[0].Rows[0]["gcpwd"].ToString().Trim();
                }
                else if (num == 2)
                {
                    _p = ds.Tables[0].Rows[0]["sczb"].ToString().Trim();
                }
                else
                {
                    _p = ds.Tables[0].Rows[0]["gcqx"].ToString().Trim();
                }
            }
            return _p;
        }

     


        /// <summary>
        /// 
        /// </summary>
        /// <param name="bigcls"></param>
        /// <param name="smcls"></param>
        /// <returns></returns>
        public string ShowSort(object bigcls, object smcls, object bigclsId, object SmallSortId)
        {
            string _result = "";
            if (bigcls != null && !string.IsNullOrEmpty(bigcls.ToString().Trim()))
            {
                _result = _result + bigcls.ToString().Trim();
            }
            if (smcls != null && !string.IsNullOrEmpty(smcls.ToString().Trim()))
            {
                _result = _result + "-" + smcls.ToString().Trim();
            }

            return _result.Trim();
        }

        public string fqstate(string qstae,string glf,string qx)
        {
            if (glf == "0.00") {
                int iqx = Convert.ToInt32(qx);
                if (iqx < 20) {
                    return "天";
                }
            }
            if (qstae.Trim() == "0" || qx == "T+9")
            {
                return "天";
            }
            if (qstae.Trim() == "4")
            {
                return "周";
            }
            return "月";
        }

        public string YdPdf(object filepath)
        {
            return "";
        }

        /// <summary>
        /// 保定类别
        /// </summary>
        /// <param name="Fselect"></param>
        public void FillSort(HtmlSelect Fselect)
        {
            Fselect.DataSource = commdal.GetSort().Tables[0].DefaultView;
            Fselect.DataTextField = "SortName";
            Fselect.DataValueField = "Id";
            Fselect.DataBind();
            Fselect.SelectedIndex = 0;
        }

        public void FillLj(HtmlSelect Fselect,string Mrstr,string Pid="1")
        {
            //Fselect.DataSource = commdal.GetHr_Lj(Pid).Tables[0].DefaultView;
            //Fselect.DataTextField = "LjKey";
            //Fselect.DataValueField = "LjUrl";
            //Fselect.DataBind();
            //if (Mrstr != "")
            //{
            //    Fselect.Items.Insert(0,new ListItem("---" + Mrstr + "---", ""));
            //}
            //Fselect.SelectedIndex = 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fddlist"></param>
        public void FillSort(DropDownList fddlist)
        {
            fddlist.DataSource = commdal.GetSort().Tables[0].DefaultView;
            fddlist.DataTextField = "SortName";
            fddlist.DataValueField = "Id";
            fddlist.DataBind();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetClientIP()
        {
            string result = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(result))
            {
                result = Request.UserHostAddress;
            }
            return result;
        }


        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                BindD();
            }
        }

        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="FstrWhere"></param>
        public virtual void BindD(){ }

        /// <summary>
        /// 保存操作日志
        /// </summary>
        /// <param name="FlogMsg"></param>
        /// <param name="Fother"></param>
        public virtual void SaveSystemLog(string FlogMsg, string Fother="") { }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetNews()
        {
            StringBuilder _sb = new StringBuilder();
            DataSet ds = commdal.GetTopNews("30", 5);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                _sb.Append("<ul>");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    _sb.AppendFormat("<li><a href=\"PreNews.aspx?Id={2}\" title=\"" + ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim() + "\" target=\"_blank\"><span>{0}]</span>{1}</a></li>", "[" +
                        ds.Tables[0].Rows[i]["NewsDate"].ToString().Trim().StrToDateTime().ToShortDateString(),
                        CommUtils.CutString(ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim(), 20) +
                        getnewszx(ds.Tables[0].Rows[i]["NewsDate"].ToString()), ds.Tables[0].Rows[i]["Id"].ToString().Trim());
                }
            }
            return _sb.Append("</ul>").ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetNewsLb(string SortId,int Fcount=5)
        {
            StringBuilder _sb = new StringBuilder();
            DataSet ds = commdal.GetTopNews(SortId, Fcount);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (SortId == "28")
                    {
                        _sb.AppendFormat("<li><a href=\"PreNews.aspx?Id={2}\" title=\"" + ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim() + "\" target=\"_blank\"><span>{0}]</span>{1}</a></li>",
               "[" + ds.Tables[0].Rows[i]["NewsDate"].ToString().Trim().StrToDateTime().ToShortDateString(),
               CommUtils.CutString(ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim(), 16) + getnewszx(ds.Tables[0].Rows[i]["NewsDate"].ToString()), ds.Tables[0].Rows[i]["Id"].ToString().Trim());
                    }
                    else
                    {
                        _sb.AppendFormat("<li><a href=\"PreNews.aspx?Id={2}\" title=\"" + ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim() + "\" target=\"_blank\"><span>{0}]</span>{1}</a></li>",
                            "[" + ds.Tables[0].Rows[i]["NewsDate"].ToString().Trim().StrToDateTime().ToShortDateString(),
                            CommUtils.CutString(ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim(), 16) + getnewszx(ds.Tables[0].Rows[i]["NewsDate"].ToString()), ds.Tables[0].Rows[i]["Id"].ToString().Trim());
                    }
                }
            }
            return _sb.ToString();
        }

        public string getnewstjtitle()
        {
            DataSet ds = commdal.QueryObjectAllSql("select * from Hr_Sort where id=31");
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["SortName"].ToString().Trim();
            }
            return "滚动新闻";
        }

        public string GetNewsTj()
        {
            StringBuilder _sb = new StringBuilder();
            DataSet ds = commdal.GetNewsTj();
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    _sb.AppendFormat("<li style=\"float: left;\"><a href=\"PreNews.aspx?Id={2}\" title=\"" + ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim() + "\" target=\"_blank\"><span>{0}]</span>{1}</a></li>",
                        "[" + ds.Tables[0].Rows[i]["NewsDate"].ToString().Trim().StrToDateTime().ToShortDateString(),
                        CommUtils.CutString(ds.Tables[0].Rows[i]["NewsTitle"].ToString().Trim(), 12) + getnewszx(ds.Tables[0].Rows[i]["NewsDate"].ToString()), ds.Tables[0].Rows[i]["Id"].ToString().Trim());
                }
            }
            return _sb.ToString();
        }

        /// <summary>
        /// 页面错误信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Error(object sender, EventArgs e)
        {
            try
            {
                Exception expt = Server.GetLastError();
                StringBuilder sb = new StringBuilder();
                Context.ClearError();
                Response.Clear();
                sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                sb.Append("<html><head><title>错误提示</title></head><body><div style='width:100%;height:100%;'><div style='width:400px;height:100px;margin:0 auto;border:solid 1px green;font-size:14px;line-height:100px;'>" + expt.Message + "</div>");
                sb.Append("</div></body></html>");
                Response.Write(sb.ToString().Trim());
                Response.Flush();
                Response.End();
            }
            catch { }
        }

        /// <summary>
        /// 将查询的值回填到控件中
        /// </summary>
        /// <param name="_querystring"></param>
        private void FillControlValue(string _querystring, string _mastercph = "ContentPlaceHolder1")
        {
            string[] _arraystr = _querystring.Split('&');
            foreach (string str in _arraystr)
            {
                string[] _arrayvalue = str.Split('=');
                if (_arrayvalue[0].Trim() == "")
                    continue;
                if (Page.Master != null)//是否使用模板页
                {
                    if (Page.Master.FindControl(_mastercph) != null)
                    {
                        if (Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0]) != null)
                        {
                            if (Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0]) is TextBox)
                            {
                                ((TextBox)Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0])).Text = _arrayvalue[1];
                            }
                            if (Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0]) is HiddenField)
                            {
                                ((HiddenField)Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0])).Value = _arrayvalue[1];
                            }
                            if (Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0]) is DropDownList)
                            {
                                ((DropDownList)Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0])).Text = _arrayvalue[1];
                            }
                            if (Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0]) is CheckBox)
                            {
                                ((CheckBox)Page.Master.FindControl(_mastercph).FindControl(_arrayvalue[0])).Checked = (_arrayvalue[1] == "1" ? true : false);
                            }
                        }
                    }
                }
                else
                    if (Page.FindControl(_arrayvalue[0]) != null)
                    {
                        if (Page.FindControl(_arrayvalue[0]) is TextBox)
                        {
                            ((TextBox)Page.FindControl(_arrayvalue[0])).Text = _arrayvalue[1];
                        }
                        if (Page.FindControl(_arrayvalue[0]) is HiddenField)
                        {
                            ((HiddenField)Page.FindControl(_arrayvalue[0])).Value = _arrayvalue[1];
                        }
                        if (Page.FindControl(_arrayvalue[0]) is DropDownList)
                        {
                            ((DropDownList)Page.FindControl(_arrayvalue[0])).SelectedValue = _arrayvalue[1];
                        }
                    }
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="url"></param>
        /// <param name="_queryparams"></param>
        public virtual void QueryGoToUrl(string url, Dictionary<string, string> _queryparams)
        {
            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<string, string> pair in _queryparams)
            {
                sb.AppendFormat("&" + pair.Key.ToString() + "={0}", pair.Value.ToString().Trim());
            }
            if (sb.ToString().Trim() != "")
            {
                Response.Redirect(url + "?action=query" + sb.ToString().Trim());
            }
            Response.Redirect(url);
        }

        /// <summary>
        /// 总的分页调用  带参数的
        /// </summary>
        /// <param name="Fds"></param>
        /// <param name="pbtn"></param>
        /// <param name="constr"></param>
        /// <returns></returns>
        public IList<object> GetPageSource(PageButton pbtn, Yd.Domain.Abstract.BaseCls.GetList_Page _GetListPage)
        {
            int CurPage = 1;
            if (Request.QueryString["Page"] != null && Request.QueryString["Page"] != "")
            {
                CurPage = Request.QueryString["Page"].StrToInt();
                if (CurPage == 0)
                {
                    CurPage = 1;
                }
            }

            int num;
            string _querystring;//带参数的查询
            IList<object> iter = _GetListPage(PageSize, CurPage, out num, out _querystring);
            switch (PageStyle)//分页的样式
            {
                case 1:
                    SetPageFooter(pbtn, num, CurPage, _querystring);
                    break;
                case 2:
                    SetPageFooter_1(pbtn, num, CurPage, _querystring);
                    break;
                default:
                    SetPageFooter(pbtn, num, CurPage, _querystring);
                    break;
            }
            return iter;
        }

        public IList<object> GetPageSourcejt(PageButton pbtn, Yd.Domain.Abstract.BaseCls.GetList_Page _GetListPage)
        {
            int CurPage = 1;
            if (Request.QueryString["Page"] != null && Request.QueryString["Page"] != "")
            {
                CurPage = Request.QueryString["Page"].StrToInt();
                if (CurPage == 0)
                {
                    CurPage = 1;
                }
            }

            int num;
            string _querystring;//带参数的查询
            IList<object> iter = _GetListPage(PageSize, CurPage, out num, out _querystring);
            switch (PageStyle)//分页的样式
            {
                case 1:
                    SetPageFooterjt(pbtn, num, CurPage, _querystring);
                    break;
                case 2:
                    SetPageFooter_1(pbtn, num, CurPage, _querystring);
                    break;
                default:
                    SetPageFooter(pbtn, num, CurPage, _querystring);
                    break;
            }
            return iter;
        }

        /// <summary>
        /// 新样式2012-05-16
        /// </summary>
        /// <param name="pbtn"></param>
        /// <param name="num"></param>
        /// <param name="CurPage"></param>
        /// <param name="_querystring"></param>
        private void SetPageFooter_1(PageButton pbtn, int num, int CurPage, string _querystring)
        {
            int _r = num % PageSize;
            int _page = 0;//页数
            if (_r == 0)
            {
                _page = (num / PageSize);
            }
            else
                _page = (num / PageSize) + 1;

            string _page1 = (_querystring.Trim() == "" ? "" : (_querystring)) + "";

            if (CurPage > _page)
            {
                CurPage = 1;
            }

            pbtn.Setlbhidcount(_page.ToString());
            pbtn.SetlbCurPage_1("&nbsp;&nbsp;<font>" + CurPage.ToString() + "</font>/" + _page.ToString() + "");
            StringBuilder sb = new StringBuilder();
            if (CurPage != 1)
            {
                sb.AppendFormat("<a href=\"{0}\">首页</a>", Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(1) + _page1);
                sb.AppendFormat("<a href=\"{0}\">上一页</a>", Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage - 1) + _page1);
            }
            else
            {
                sb.AppendFormat("<a href=\"{0}\">首页</a>", "#");
                sb.AppendFormat("<a href=\"{0}\">上一页</a>", "#");
            }

            int _s = 1;//开始页
            int _e = 0;//结束页

            if (CurPage <= CommUtils._MiddlePage)
            {
                _s = 1;
                if (_page > (CommUtils._MiddlePage * 2))
                    _e = (CommUtils._MiddlePage * 2);
                else
                    _e = _page;
            }
            else
            {
                _s = CurPage - (CommUtils._MiddlePage - 1);
                _e = CurPage + CommUtils._MiddlePage;

                if (_e > _page)
                {
                    _e = _page;
                    _s = _page - (CommUtils._MiddlePage * 2 - 1);
                }
            }

            for (int i = _s; i <= _e; i++)
            {
                if (i == CurPage)
                    sb.AppendFormat("<a href=\"{0}\" style=\"border:solid 1px Red;color:Red;\">{1}</a>", "#", i.ToString());
                else
                    sb.AppendFormat("<a href=\"{0}\">{1}</a>", Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(i) + _page1, i.ToString());
            }

            if (CurPage < _page)
            {
                sb.AppendFormat("<a href=\"{0}\">下一页</a>", Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + _page1);
                sb.AppendFormat("<a href=\"{0}\">尾页</a>", Request.CurrentExecutionFilePath + "?Page=" + _page.ToString() + _page1);
            }
            else
            {
                sb.AppendFormat("<a href=\"{0}\">下一页</a>", "#");
                sb.AppendFormat("<a href=\"{0}\">尾页</a>", "#");
            }
            sb.Append("<script type=\"text/javascript\">");
            sb.Append("function aa(){");
            sb.Append("var pagenum = document.getElementById(\"atpage\").value;");
            sb.Append("try{window.location.href=window.location.href+/\"?Page=\"+pagenum; }");
            sb.Append("catch(e){}");
            sb.Append("return false;}");
            sb.Append("</script>");
            sb.AppendFormat("<input type=\"text\" style=\"width:30px;\" value=\"\" name=\"atpage\" id=\"atpage\">");
            sb.AppendFormat("<input type=\"submit\" value=\"跳转\" onclick=\"aa();\" style=\"border:1px solid\">");

            pbtn.Setfy_1(sb.ToString());

            if (_page1.Trim() != "")
            {
                FillControlValue(_querystring);
            }
        }

        public void SetPageFooter(PageButton pbtn, int num, int CurPage, string _querystring)
        {
            if (pbtn == null)
            {
                return;
            }

            int _r = num % PageSize;
            int _page = 0;//页数
            if (_r == 0)
            {
                _page = (num / PageSize);
            }
            else
                _page = (num / PageSize) + 1;


            if (CurPage > _page)
            {
                CurPage = 1;
            }

            pbtn.Setlbhidcount(_page.ToString());

            string _page1 = (_querystring.Trim() == "" ? "" : (_querystring)) + "";
            string _url = "";
            if (string.IsNullOrEmpty(_url))
            {
                _url = Request.CurrentExecutionFilePath;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("<script type=\"text/javascript\">");
            sb.Append("function aa(){");
            sb.Append("var pagenum = document.getElementById(\"atpage\").value;");
            sb.Append("window.location.href=\"http://" + Request.Url.Authority + _url + "?Page=\"+pagenum+\"" + _querystring + "\"; }");
            sb.Append("</script>");
            sb.AppendFormat("<input type=\"text\" style=\"width:30px; border:1px solid; border-color:#ccc;\" value=\"\" name=\"atpage\" id=\"atpage\">");
            sb.AppendFormat("&nbsp;<input type=\"submit\" value=\"跳转\" onclick=\"aa();return false;\">");

            pbtn.SetlbCount(String.Format(@"{0}&nbsp;&nbsp;共有&nbsp;{1}&nbsp;个记录", sb.ToString(), num.ToString()));

            pbtn.SetlbCurPage("&nbsp;&nbsp;当前页:<font color='red'>" + CurPage.ToString() + "</font>/" + _page.ToString() + "&nbsp;&nbsp;" + PageSize.ToString() + "个/页");

            
            if (CurPage != 1)
            {
                pbtn.SethlnkHead(_url + "?Page=" + Convert.ToString(1) + _page1);
                pbtn.SethlnkPrev(_url + "?Page=" + Convert.ToString(CurPage - 1) + _page1);
            }

            if (CurPage < _page)
            {
                pbtn.SethlnkNext(_url + "?Page=" + Convert.ToString(CurPage + 1) + _page1);
                pbtn.SethlnkEnd(_url + "?Page=" + _page.ToString() + _page1);
            }
            if (_page1.Trim() != "")
            {
                FillControlValue(_querystring);
            }
        }

        private void SetPageFooterjt(PageButton pbtn, int num, int CurPage, string _querystring)
        {
            if (pbtn == null)
            {
                return;
            }

            int _r = num % PageSize;
            int _page = 0;//页数
            if (_r == 0)
            {
                _page = (num / PageSize);
            }
            else
                _page = (num / PageSize) + 1;


            if (CurPage > _page)
            {
                CurPage = 1;
            }

            pbtn.Setlbhidcount(_page.ToString());

            pbtn.SetlbCount("&nbsp;&nbsp;共有&nbsp;" + num.ToString() + "&nbsp;个记录");

            pbtn.SetlbCurPage("&nbsp;&nbsp;当前页:<font color='red'>" + CurPage.ToString() + "</font>/" + _page.ToString() + "&nbsp;&nbsp;" + PageSize.ToString() + "个/页");

            string _page1 = (_querystring.Trim() == "" ? "" : (_querystring)) + "";
            string _url = "";
            if (string.IsNullOrEmpty(_url))
            {
                _url = Request.CurrentExecutionFilePath;
            }
            if (CurPage != 1)
            {
                pbtn.SethlnkHead("/html"+_url.Replace(".aspx", "-1" + ".html"));
                pbtn.SethlnkPrev("/html" + _url.Replace(".aspx", "-" + Convert.ToString(CurPage - 1) + ".html"));
            }

            if (CurPage < _page)
            {
                pbtn.SethlnkNext("/html" + _url.Replace(".aspx", "-" + Convert.ToString(CurPage + 1) + ".html"));
                pbtn.SethlnkEnd("/html" + _url.Replace(".aspx", "-" + _page.ToString() + ".html"));
            }
            //if (_page1.Trim() != "")
            //{
            //    FillControlValue(_querystring);
            //}
        }


        /// <summary>
        /// 总的分页调用
        /// </summary>
        /// <param name="Fds"></param>
        /// <param name="pbtn"></param>
        /// <param name="constr"></param>
        /// <returns></returns>
        public IList<object> GetPageSource(PageButton pbtn, object _object, Yd.Domain.Abstract.BaseCls.GetList _GetList)
        {
            int CurPage = 1;
            if (Request.QueryString["Page"] != null && Request.QueryString["Page"] != "")
            {
                CurPage = Request.QueryString["Page"].StrToInt();
            }
            int num;
            IList<object> iter = _GetList(_object, PageSize, CurPage, out num);
            SetPageFooter(pbtn, num, CurPage, "");
            return iter;
        }


        public IList<object> GetPageSourceTs(StaticPage pbtn, Yd.Domain.Abstract.BaseCls.GetListTS _GetList)
        {
            int CurPage = 1;
            if (Request.Form["Page"] != null && Request.Form["Page"] != "")
            {
                CurPage = Request.Form["Page"].StrToInt();
            }
            int num;
            IList<object> iter = _GetList(PageSize, CurPage, out num);
            SetPageFooterq(pbtn, num, CurPage);
            return iter;
        }

        private void SetPageFooterq(StaticPage pbtn, int num, int CurPage)
        {
            int _r = num % PageSize;
            int _page = 0;//页数
            if (_r == 0)
            {
                _page = (num / PageSize);
            }
            else
                _page = (num / PageSize) + 1;
            if (CurPage > _page)
            {
                CurPage = 1;
            }
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<div class=\"pagination clearfix\"><ul class=\"clearfix fr\">");

            for (int i = 1; i <= _page; i++)
            {
                if (i == CurPage)
                {
                    sb.AppendLine("<li><span>"+i.ToString()+"</span></li>");
                }
                else
                {
                    if (Request.Url.ToString().IndexOf("cwmx.aspx") != -1)
                    {
                        if(Request["action"].Trim() == "lixi")
                        {
                            sb.AppendLine("<li><a class=\"page\" href=\"javascript:fundDetailInterestPageJumplixi('" + i.ToString() + "')\">" + i.ToString() + "</a></li>");
                        }
                        else
                        sb.AppendLine("<li><a class=\"page\" href=\"javascript:fundDetailInterestPageJump1('" + i.ToString() + "')\">" + i.ToString() + "</a></li>");
                    }
                    else
                    {
                        sb.AppendLine("<li><a class=\"page\" href=\"javascript:fundDetailInterestPageJump('" + i.ToString() + "')\">" + i.ToString() + "</a></li>");
                    }
                }
            }

            sb.AppendLine("</ul>");
            sb.AppendLine("<input value=" + CurPage.ToString() + " type=hidden name=page>");
            sb.AppendLine("<input value=" + _page.ToString() + " type=hidden name=pages>");
            sb.AppendLine("<input value=" + num.ToString() + " type=hidden name=items>");
            sb.AppendLine("</div>");
            pbtn.SetlbCount(sb.ToString());
        }
    }
}
